const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const app = express();
app.use(function(req,res,next) {
    //开放权限,允许跨域
    res.header("Access-Control-Allow-Origin", "*");
    next();
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//积分专区
app.get('/getpoint', function(req, res) {
    var url = "http://wap.pusai.net/proxy/api/custom";          
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    })
});
//商品分类
app.get('/getcategory', function(req, res) {
    var url = "http://wap.pusai.net/proxy/api/category";          
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    })
});
//分类商品
app.get('/getcategoryproduct', function(req, res) {
    var url = `http://wap.pusai.net/proxy/api/product/list?categoryId=${req.query.categoryId}&pageNum=${req.query.pageNum}&sort=${req.query.sort}`;          
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    })
});
//活动
app.get('/getactivity', function(req, res) {
    var url = "http://wap.pusai.net/proxy/api/activity/list";          
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    })
});
//猜你喜欢
app.get('/getlike', function(req, res) {
    var url = `http://wap.pusai.net/proxy/api/index/like?pageNum=${req.query.pageNum}`;     
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    })
});
//启动服务器
app.listen(3005, function() {
    console.log('start at http://127.0.0.1:3005');
});